-
Notifications
You must be signed in to change notification settings - Fork 3
feat: add tool usage recording for blocking responses interceptor #122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
b0290a7 to
ee80a4b
Compare
intercept/responses/base_test.go
Outdated
| expected: nil, | ||
| }, | ||
| { | ||
| name: "nested_object", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: _with_trailing_spaces
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
responses_integration_test.go
Outdated
| recordedTools[0].InterceptionID = tc.expectToolRecorded.InterceptionID // ignore interception id | ||
| recordedTools[0].CreatedAt = tc.expectToolRecorded.CreatedAt // ignore time |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alternatively you can clear both fields if ignored
intercept/responses/base.go
Outdated
| func (i *responsesInterceptionBase) parseJSONArgs(raw string) recorder.ToolArgs { | ||
| if trimmed := strings.TrimSpace(raw); trimmed != "" { | ||
| var args recorder.ToolArgs | ||
| if err := json.Unmarshal([]byte(trimmed), &args); err == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we do something if JSON is borked?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed; errors should be handled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Logic was wrong here. Updated it to match what is done in chat completions.
| ID: "resp_789", | ||
| Output: []oairesponses.ResponseOutputItemUnion{ | ||
| { | ||
| Type: "function_call", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm... do we need another test for function_call with broken args?
intercept/responses/base.go
Outdated
| } | ||
| } | ||
|
|
||
| func (i *responsesInterceptionBase) parseJSONArgs(raw string) recorder.ToolArgs { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method isn't well named. It should indicate that it's just for tools.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated name
intercept/responses/base.go
Outdated
| func (i *responsesInterceptionBase) parseJSONArgs(raw string) recorder.ToolArgs { | ||
| if trimmed := strings.TrimSpace(raw); trimmed != "" { | ||
| var args recorder.ToolArgs | ||
| if err := json.Unmarshal([]byte(trimmed), &args); err == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed; errors should be handled.
intercept/responses/base.go
Outdated
| // recodring other function types to be considered: https://github.com/coder/aibridge/issues/121 | ||
| switch item.Type { | ||
| case "function_call": | ||
| args = i.parseJSONArgs(item.Arguments) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this necessary to do? Why can't we pass the string value like we do for the others?
By the time it's stored in the db it's a string anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wanted to keep it consistent with chat completions.
You are right this seems redundant with how we store things in DB but then recorder API should change (ToolUsageRecord should have Args as string instead of any)?
responses_integration_test.go
Outdated
| recordedTools := mockRecorder.RecordedToolUsages() | ||
| if tc.expectToolRecorded != nil { | ||
| require.Len(t, recordedTools, 1) | ||
| recordedTools[0].InterceptionID = tc.expectToolRecorded.InterceptionID // ignore interception id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide a reason why.
8ecf6e4 to
7bdf03a
Compare
mtojek
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All good on my end!
7bdf03a to
11d3c46
Compare

No description provided.